<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        @import-normalize;
        .one{
            width: 200px;
            height: 200px;
            background-color: pink;
        }
        .two{
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="one" @click.stop="one">点我可以控制“哈哈哈哈”的显隐 （点其他空白的地方会让“哈哈哈哈”消失）

<!--            <div class="two" @click.stop="two">222</div>-->
        </div>
        <div v-show="isShow"> 哈哈哈哈</div>
    </div>
<!--    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>-->
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                isShow: true
            },
            mounted(){
               document.addEventListener('click', this.handleClick)
            },
            beforeDestroy(){
                document.removeEventListener('click', this.handleClick)
            },

            methods: {
                one(){
                    console.log(111);
                    this.isShow = !this.isShow
                },
                two(){
                    console.log(2222);
                },
                handleClick(e){
                    console.log('哈哈哈哈正在显示吗', this.isShow)
                    this.isShow && (this.isShow = false)
                }
            },

        })
    </script>
</body>

</html>
